Distribution was not found and is required by the application 路 Issue #4409 路 pyinstaller/pyinstaller 路 GitHub 您所在的位置:网站首页 pyinstaller importlib_metadata Distribution was not found and is required by the application 路 Issue #4409 路 pyinstaller/pyinstaller 路 GitHub

Distribution was not found and is required by the application 路 Issue #4409 路 pyinstaller/pyinstaller 路 GitHub

2023-08-22 17:56| 来源: 网络整理| 查看: 265

For the record, I did figure out how to store the hooks file in the repo (so it is saved with my VCS), and include it with pyinstaller at the command-line, as follows. You can read more about hooks here: https://pythonhosted.org/PyInstaller/hooks.html

It would still be better if pyinstaller could auto-detect the need for the metadata (perhaps this can be linked in with the new built-in importlib-metadata import now available in 3.8.0), but here's how to do it at the moment:

Create a hook file - hook-module.py, (substitute one of your custom module names for module, ) and place the hook file anywhere you want in your package folder hierarchy. This must be a module that gets imported in your scripts. I just used the module name that is the same as my package name.

I have the semi-standard package setup with a source folder, a tests folder, etc. and I chose to add a new hooks folder in the package root directory and placed my hook file there. Put the following in the hook file:

from PyInstaller.utils.hooks import copy_metadata datas = copy_metadata('mypackage')

where you substitute your package name for mypackage (with quotes around it, as a string). Note that if you define or update the datas variable somewhere else for PyInstaller, you will need to modify the above to account for that.

Then when running PyInstaller, just add the --additional-hooks-dir=.\\hooks argument. This assumes you added a hooks directory to your package root folder, and with a Windows style path.

That's it. PyInstaller will search the additional hooks folder, and find the custom hook file and use it.

Note: You still have to make sure that the metadata is there and has been updated before running PyInstaller. For example, you might need to run python setup.py sdist to get setuptools to update the metadata, or may need to update it directly, depending how you have your package setup.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有